home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 4 / Example 4.7 / terrain.h < prev   
Encoding:
C/C++ Source or Header  |  2006-06-28  |  1.1 KB  |  59 lines

  1. #ifndef _TERRAIN_
  2. #define _TERRAIN_
  3.  
  4. #include <d3dx9.h>
  5. #include <vector>
  6. #include "heightmap.h"
  7. #include "debug.h"
  8.  
  9. struct TERRAINVertex
  10. {
  11.     TERRAINVertex(){}
  12.     TERRAINVertex(D3DXVECTOR3 pos, D3DXVECTOR2 _uv1, D3DXVECTOR2 _uv2)
  13.     {
  14.         position = pos;
  15.         normal = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
  16.         uv1 = _uv1;
  17.         uv2 = _uv2;
  18.     }
  19.  
  20.     D3DXVECTOR3 position, normal;
  21.     D3DXVECTOR2 uv1, uv2;
  22.  
  23.     static const DWORD FVF;
  24. };
  25.  
  26. struct PATCH{
  27.     PATCH();
  28.     ~PATCH();
  29.     void Release();
  30.     HRESULT CreateMesh(HEIGHTMAP &hm, RECT source, IDirect3DDevice9* Dev);
  31.     void Render();
  32.  
  33.     IDirect3DDevice9* m_pDevice;
  34.     ID3DXMesh *m_pMesh;
  35. };
  36.  
  37. class TERRAIN{
  38.     friend class APPLICATION;
  39.     public:
  40.         TERRAIN();        
  41.         void Init(IDirect3DDevice9* Dev, INTPOINT _size);
  42.         void Release();
  43.         void GenerateRandomTerrain(int numPatches);
  44.         void CreatePatches(int numPatches);
  45.         void CalculateAlphaMaps();
  46.         void Render();
  47.  
  48.     private:
  49.  
  50.         INTPOINT m_size;
  51.         IDirect3DDevice9* m_pDevice; 
  52.  
  53.         HEIGHTMAP *m_pHeightMap;
  54.         std::vector<PATCH*> m_patches;
  55.         std::vector<IDirect3DTexture9*> m_diffuseMaps, m_alphaMaps;
  56.         D3DMATERIAL9 m_mtrl;
  57. };
  58.  
  59. #endif